package sifcom.servlet;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sifcom.Entidades.Factory.Socios;

import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.repackaged.org.json.JSONException;

public class SocioServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 2771302219368713503L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp){
		
		if(req.getParameter("ced") ==null && req.getParameter("nombres") ==null && req.getParameter("apellidos") == null)
		{
		Socios data = new Socios();
		String datos = data.getDataSocio();
			
			/*
			SocioData sd = new SocioData();
			String datos=sd.getDataSocio();*/
		try {
			resp.getWriter().write(datos);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
		else
		{
			
			Socios data = new Socios();
			String datos = data.SearchSocio(req.getParameter("ced") != null ? req.getParameter("ced").toString() : "", 
					req.getParameter("nombres") !=null ? req.getParameter("nombres").toString() : "", 
				    req.getParameter("apellidos") !=null ? req.getParameter("apellidos").toString() : "");
			
			/*
			SocioData sd = new SocioData();
			
			String datos = sd.SearchSocio(req.getParameter("ced") != null ? req.getParameter("ced").toString() : "", 
					req.getParameter("nombres") !=null ? req.getParameter("nombres").toString() : "", 
				    req.getParameter("apellidos") !=null ? req.getParameter("apellidos").toString() : ""); */
			try {
				resp.getWriter().write(datos);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp){
		try {
			Socios data = new Socios(req.getReader());	
			
			/*SocioData sd = new SocioData();
			sd.SetSocio(req.getReader());*/
			this.doGet(req, resp);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (EntityNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
